﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Login;
public class UserInput : MonoBehaviour {
    public LoginUI loginUI;
    public GameObject nameInput;
    public GameObject passWordInput;
    private string userName = "";
    private string passWord = "";
    public UILabel errInfo;

    public List<UITweener> tweenList;

    public void Show() {
        gameObject.SetActive(true);
        Reset();
        PlayTween();
    }

    public void Hide() {
        gameObject.SetActive(false);
    }

    public void Reset()
    {
        userName = "";
        passWord = "";
        nameInput.GetComponent<UIInput>().value = "";
        passWordInput.GetComponent<UIInput>().value = "";
    }

  
    void PlayTween() 
    {
        foreach (var item in tweenList)
        {
            item.ResetToBeginning();
            item.PlayForward();
        }
    }

    public void Init() {
        userName = "";
        passWord = "";
        nameInput.GetComponent<UIInput>().value = "";
        passWordInput.GetComponent<UIInput>().value = "";
        ErrInfoFalse();
    }


    public void ErrInfoFalse() 
    {
        errInfo.gameObject.SetActive(false);
    }
    /// <summary>
    /// 关闭按钮
    /// </summary>
    public void OnCloseButtonClick() 
    {
        this.gameObject.SetActive(false);
        ErrInfoFalse();
    }
  

    /// <summary>
    /// 忘记密码
    /// </summary>
    public void OnForgetPassWord() 
    {
     
    }
    /// <summary>
    /// 游客登录
    /// </summary>
    public void OnTouristsLogin() 
    {

    }
    /// <summary>
    /// 快速注册
    /// </summary>
    public void OnRegistButtonClick() 
    {
        /*
        nameInput.GetComponent<UIInput>().value = "";
        passWordInput.GetComponent<UIInput>().value = "";
        Hide();
        loginUI.ShowRegistPanel();
        */
    }

    /// <summary>
    /// 立即登录
    /// </summary>
    public void OnLoginButton() 
    {

        
        userName = nameInput.GetComponent<UIInput>().value;
        passWord = passWordInput.GetComponent<UIInput>().value;


        if (userName == "" || passWord == "")
        {
            errInfo.gameObject.SetActive(true);
        }
        else
        {
            this.gameObject.SetActive(false);

            StaticData.UserName = userName;
            StaticData.PassWord = passWord;

            loginUI.manager.isAuthPassed = true;
            loginUI.manager.SwitchState(LoginState.GetServerList);

          
           
        }


    }


}
